--[[
    KOD    
--]]

function removeHex(string)
    if type(string) ~= "string" then return false end
    while(string ~= string.gsub(string, "#%x%x%x%x%x%x", "")) do
        string = string.gsub(string, "#%x%x%x%x%x%x", "")
    end
    return string or false
end

function getTimeElapsed(last, timeout)
    local timeElapsed = ((last+timeout)-getTickCount())/1000
    return string.format("%.1f", timeElapsed)
end

local allowed = { { 48, 57 }, { 65, 90 }, { 97, 122 } } -- numbers/lowercase chars/uppercase chars

function generateString(len)
    if not tonumber(len) then return false end
    local str = ""
    for i = 1, len do
        local charlist = allowed[math.random(1, 3)]
        str = str..string.char(math.random(charlist[1], charlist[2]))
    end
    return (str or false)
end

function findPlayer(target)
	local player = false
	local searchType = (tonumber(target) and "id" or "name")
	for i,v in pairs(getElementsByType("player")) do
		if searchType == "id" then
			if getElementData(v, "id") == tonumber(target) then
				player = v
				break
			end
		else
			if string.find(string.gsub(string.lower(getPlayerName(v)),"#%x%x%x%x%x%x", ""), string.lower(target), 1, true) then
				player = v
				break
			end
		end
	end
	return player
end

function formatNumber(number, sep)
	assert(type(tonumber(number))=="number", "Bad argument @'formatNumber' [Expected number at argument 1 got "..type(number).."]")
	assert(not sep or type(sep)=="string", "Bad argument @'formatNumber' [Expected string at argument 2 got "..type(sep).."]")
	local money = number
	for i = 1, tostring(money):len()/3 do
		money = string.gsub(money, "^(-?%d+)(%d%d%d)", "%1"..sep.."%2")
	end
	return money
end